home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Mark Pilgrim / Kant Generator Pro 1.0.1 / source / Shell ƒ / menus.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-30  |  17.7 KB  |  673 lines  |  [TEXT/MMCC]

  1. #include "menus.h"
  2. #include "graphics.h"
  3. #include "help.h"
  4. #include "environment.h"
  5. #include "error.h"
  6. #include "file interface.h"
  7. #include "resource utilities.h"
  8. #include "print meat.h"
  9. #include "text twiddling.h"
  10. #include "util.h"
  11. #include "graphics dispatch.h"
  12. #include "window layer.h"
  13. #include "program globals.h"
  14. #include "kant.h"
  15. #include "kantinuous.h"
  16. #include "kant load-save.h"
  17. #include "kant parser dispatch.h"
  18. #include "kant build files.h"
  19. #include "kant build meat.h"
  20. #include "kant build gui.h"
  21.  
  22. static    MenuHandle        gAppleMenu=0L;
  23. static    MenuHandle        gFileMenu=0L;
  24. static    MenuHandle        gEditMenu=0L;
  25. static    MenuHandle        gOptionsMenu=0L;
  26. static    MenuHandle        gModulesMenu=0L;
  27. static    MenuHandle        gInsertMenu=0L;
  28. MenuHandle        gBuildMenu=0L;
  29. static    MenuHandle        gSpeedMenu=0L;
  30.  
  31. #define NUM_MODULES        (CountMItems(gModulesMenu)-modules_first+1)
  32.  
  33. enum
  34. {
  35.     speedMenu = 200,
  36.     
  37.     appleMenu = 400, fileMenu, editMenu, optionsMenu, modulesMenu, insertMenu, buildMenu,
  38.     
  39.     aboutItem = 1, aboutMSGItem, otherMSGItem, helpPointerItem,
  40.     
  41.     newItem = 1, openItem, file_unused1, closeItem, saveItem, saveAsItem, file_unused2,
  42.         pageSetupItem, printItem, file_unused3, quitItem,
  43.     
  44.     undoItem = 1, edit_unused0, cutItem, copyItem, pasteItem, clearItem, edit_unused1, selectAllItem,
  45.     
  46.     resolveItem = 1, alwaysResolveItem, option_unused1, speedMenuPtr, option_unused3,
  47.         kantinuousItem,
  48.     
  49.     modules_default = 1, modules_other, modules_unused, modules_first,
  50.     
  51.     sectionItem = 1, paragraphItem, sentenceItem, mainClauseItem, introClauseItem,
  52.         throwawayClauseItem, proofItem, throwawaySentenceItem,
  53.     
  54.     build_new = 1, build_open, build_unused1, build_new_ref, build_new_instant,
  55.         build_edit_ref, build_delete_ref, build_unused2, build_show_instant,
  56.         build_show_all_instant, build_hide_all_instant,
  57.     
  58.     delay0Item = 1, delay6Item, delay12Item, delay30Item, delay60Item
  59. };
  60.  
  61. /*-----------------------------------------------------------------------------------*/
  62. /* internal stuff for menus.c                                                        */
  63.  
  64. static    void HandleAppleMenu(short menuItem);
  65. static    void HandleFileMenu(short menuItem);
  66. static    void HandleEditMenu(short menuItem, Boolean alreadyPassedThrough);
  67. static    void HandleOptionsMenu(short menuItem);
  68. static    void HandleModulesMenu(short menuItem);
  69. static    void HandleInsertMenu(short menuItem);
  70. static    void HandleBuildMenu(short menuItem);
  71. static    void HandleSpeedMenu(short menuItem);
  72. static    void EDItem(MenuHandle theMenu, short theItem, Boolean theCondition);
  73.  
  74. Boolean InitTheMenus(void)
  75. {
  76.     Handle            MBARHandle;
  77.     FSSpec            theFS;
  78.     
  79.     if ((MBARHandle=GetNewMBar(400))==0L)        /* sez which menus are in menu bar. */
  80.         return FALSE;
  81.     SetMenuBar(MBARHandle);                        /* set this to be THE menu bar to use. */
  82.     
  83.     if ((gAppleMenu=GetMHandle(appleMenu))==0L)    /* GetNewMBar also got menu handles of */
  84.         return FALSE;
  85.     if ((gFileMenu=GetMHandle(fileMenu))==0L)    /* every menu it includes, so just */
  86.         return FALSE;
  87.     if ((gEditMenu=GetMHandle(editMenu))==0L)    /* grab these handles and assign them */
  88.         return FALSE;
  89.     if ((gOptionsMenu=GetMHandle(optionsMenu))==0L)
  90.         return FALSE;
  91.     if ((gModulesMenu=GetMHandle(modulesMenu))==0L)
  92.         return FALSE;
  93.     if ((gInsertMenu=GetMHandle(insertMenu))==0L)
  94.         return FALSE;
  95.     if ((gBuildMenu=GetMHandle(buildMenu))==0L)
  96.         return FALSE;
  97.     if ((gSpeedMenu=GetMenu(speedMenu))==0L)
  98.         return FALSE;
  99.     
  100.     InsertMenu(gSpeedMenu, -1);
  101.     
  102.     AddResMenu(gAppleMenu, 'DRVR');                /* adds control panels to apple menu */
  103.     
  104.     if (BuildModulesList(gModulesMenu)!=noErr)
  105.     {
  106.         HandleError(kCantFindModulesFolder, FALSE, FALSE);
  107.         theFS.name[0]=0x00;
  108.         UseTheModule(&theFS, TRUE);    /* revert to built-in */
  109.     }
  110.     
  111.     if (!gUseDefault)
  112.         RebuildReferencesList();
  113.     
  114.     AdjustMenus();                                /* dim/enable/check/mark menus/items */
  115.     DrawMenuBar();                                /* draws the actual menu bar */
  116.     
  117.     return TRUE;
  118. }
  119.  
  120. void ShutDownTheMenus(void)
  121. {
  122.     gAppleMenu=(MenuHandle)SafeReleaseResource((Handle)gAppleMenu);
  123.     gFileMenu=(MenuHandle)SafeReleaseResource((Handle)gFileMenu);
  124.     gEditMenu=(MenuHandle)SafeReleaseResource((Handle)gEditMenu);
  125.     gOptionsMenu=(MenuHandle)SafeReleaseResource((Handle)gOptionsMenu);
  126.     gModulesMenu=(MenuHandle)SafeReleaseResource((Handle)gModulesMenu);
  127.     gInsertMenu=(MenuHandle)SafeReleaseResource((Handle)gInsertMenu);
  128.     gBuildMenu=(MenuHandle)SafeReleaseResource((Handle)gBuildMenu);
  129.     gSpeedMenu=(MenuHandle)SafeReleaseResource((Handle)gSpeedMenu);
  130. }
  131.  
  132. void AdjustMenus(void)
  133. {
  134.     short            kind;
  135.     WindowPtr        front, frontDoc, mainWindow, buildWindow;
  136.     Boolean            isRef;
  137.     Str255            theStr;
  138.     Boolean            gotone;
  139.     short            i;
  140.     unsigned char    *otherStr="\pOther...";
  141.     
  142.     front=FrontWindow();
  143.     kind=front ? ((WindowPeek)front)->windowKind : 0;
  144.     frontDoc=GetFrontDocumentWindow();
  145.     mainWindow=GetIndWindowPtr(kMainWindow);
  146.     buildWindow=GetIndWindowPtr(kBuildWindow);
  147.     isRef=RefHighlightedQQ(buildWindow);
  148.     
  149.     CheckItem(gOptionsMenu, alwaysResolveItem, gAlwaysResolve ? TRUE : FALSE);
  150.     CheckItem(gSpeedMenu, delay0Item, (gSpeedDelay==0));
  151.     CheckItem(gSpeedMenu, delay6Item, (gSpeedDelay==6));
  152.     CheckItem(gSpeedMenu, delay12Item, (gSpeedDelay==12));
  153.     CheckItem(gSpeedMenu, delay30Item, (gSpeedDelay==30));
  154.     CheckItem(gSpeedMenu, delay60Item, (gSpeedDelay==60));
  155.     
  156.     SetItem(gBuildMenu, build_edit_ref, isRef ? "\pEdit reference" : "\pEdit instantiation");
  157.     SetItem(gBuildMenu, build_delete_ref, isRef ? "\pDelete reference" : "\pDelete instantiation");
  158.     SetItem(gBuildMenu, build_show_instant, RefClosedQQ(buildWindow) ? "\pShow instantiations" :
  159.         "\pHide instantiations");
  160.     SetItemStyle(gBuildMenu, build_new, extend);
  161.     SetItemStyle(gBuildMenu, build_open, extend);
  162.     SetItemStyle(gBuildMenu, build_new_ref, condense+extend);
  163.     SetItemStyle(gBuildMenu, build_new_instant, condense);
  164.     
  165.     SetItemMark(gModulesMenu, modules_default, gUseDefault ? '◊' : noMark);
  166.     SetItemMark(gModulesMenu, modules_other, noMark);
  167.         
  168.     gotone=gUseDefault;
  169.     for (i=0; i<NUM_MODULES; i++)
  170.     {
  171.         if (!gotone)
  172.         {
  173.             GetItem(gModulesMenu, i+modules_first, theStr);
  174.             if (Mymemcompare((Ptr)theStr, (Ptr)gModuleFS.name, theStr[0]+1))
  175.                 gotone=TRUE;
  176.             SetItemMark(gModulesMenu, i+modules_first, gotone ? '◊' : noMark);
  177.         }
  178.         else SetItemMark(gModulesMenu, i+modules_first, noMark);
  179.     }
  180.     
  181.     if (!gotone)
  182.     {
  183.         SetItemMark(gModulesMenu, modules_other, '◊');
  184.         Mymemcpy((Ptr)theStr, (Ptr)otherStr, otherStr[0]+1);
  185.         AppendStr255(theStr, "\p (");
  186.         AppendStr255(theStr, gModuleFS.name);
  187.         AppendStr255(theStr, "\p)");
  188.         SetItem(gModulesMenu, modules_other, theStr);
  189.     }
  190.     else SetItem(gModulesMenu, modules_other, "\pOther...");
  191.     
  192.     EDItem(gAppleMenu, 0, !gInProgress);
  193.     EDItem(gAppleMenu, aboutItem, !gInProgress);
  194.     EDItem(gAppleMenu, aboutMSGItem, !gInProgress);
  195.     EDItem(gAppleMenu, otherMSGItem, !gInProgress);
  196.     EDItem(gAppleMenu, helpPointerItem, !gInProgress);
  197.     EDItem(gFileMenu, 0, !gInProgress);
  198.     EDItem(gEditMenu, 0, !gInProgress);
  199.     EDItem(gOptionsMenu, 0, !gInProgress);
  200.     EDItem(gModulesMenu, 0, !gInProgress);
  201.     EDItem(gInsertMenu, 0, !gInProgress);
  202.     EDItem(gBuildMenu, 0, !gInProgress);
  203.     
  204.     if (gInProgress)
  205.         return;
  206.     
  207.     EDItem(gFileMenu, newItem, TRUE);
  208.     EDItem(gFileMenu, openItem, TRUE);
  209.     EDItem(gFileMenu, closeItem, front!=0L);
  210.     EDItem(gFileMenu, saveItem, (mainWindow!=0L) && (WindowHasLayer(mainWindow)) &&
  211.         (WindowIsModifiedQQ(mainWindow)));
  212.     EDItem(gFileMenu, saveAsItem, mainWindow!=0L);
  213.     EDItem(gFileMenu, pageSetupItem, TRUE);
  214.     EDItem(gFileMenu, printItem, (frontDoc!=0L) && (WindowHasLayer(frontDoc)) &&
  215.         (GetWindowTE(frontDoc)!=0L));
  216.     EDItem(gFileMenu, quitItem, TRUE);
  217.     
  218.     EDItem(gEditMenu, undoItem, kind<0);
  219.     EDItem(gEditMenu, cutItem, (frontDoc!=0L) && (frontDoc==mainWindow) && (AnyHighlightedQQ(frontDoc)));
  220.     EDItem(gEditMenu, copyItem, (frontDoc!=0L) && (frontDoc==mainWindow) && (AnyHighlightedQQ(frontDoc)));
  221.     EDItem(gEditMenu, pasteItem, (frontDoc!=0L) && (frontDoc==mainWindow) && (AnyTextInScrapQQ()));
  222.     EDItem(gEditMenu, clearItem, (frontDoc!=0L) && (frontDoc==mainWindow) && (AnyHighlightedQQ(frontDoc)));
  223.     EDItem(gEditMenu, selectAllItem, (frontDoc!=0L) && (frontDoc==mainWindow) && (AnyTextQQ(frontDoc)));
  224.     
  225.     EDItem(gOptionsMenu, resolveItem, (mainWindow!=0L));
  226.     EDItem(gOptionsMenu, speedMenuPtr, TRUE);
  227.     EDItem(gOptionsMenu, kantinuousItem, gUseDefault);
  228.     
  229.     EDItem(gBuildMenu, build_new, buildWindow==0L);
  230.     EDItem(gBuildMenu, build_open, buildWindow==0L);
  231.     EDItem(gBuildMenu, build_new_ref, buildWindow!=0L);
  232.     EDItem(gBuildMenu, build_new_instant, (buildWindow!=0L) && (AnyHighlightedQQ(buildWindow)));
  233.     EDItem(gBuildMenu, build_edit_ref, (buildWindow!=0L) && (AnyHighlightedQQ(buildWindow)));
  234.     EDItem(gBuildMenu, build_delete_ref, (buildWindow!=0L) && (AnyHighlightedQQ(buildWindow)));
  235.     EDItem(gBuildMenu, build_show_instant, (buildWindow!=0L) && (AnyHighlightedQQ(buildWindow)) && isRef);
  236.     EDItem(gBuildMenu, build_show_all_instant, (buildWindow!=0L) && (AnyTextQQ(buildWindow)));
  237.     EDItem(gBuildMenu, build_hide_all_instant, (buildWindow!=0L) && (AnyTextQQ(buildWindow)));
  238. }
  239.  
  240. void HandleMenu(long mSelect)
  241. {
  242.     short            menuID = HiWord(mSelect);
  243.     short            menuItem = LoWord(mSelect);
  244.     
  245.     switch (menuID)
  246.     {
  247.         case appleMenu:
  248.             HandleAppleMenu(menuItem);
  249.             break;
  250.         case fileMenu:
  251.             HandleFileMenu(menuItem);
  252.             break;    
  253.         case editMenu:
  254.             HandleEditMenu(menuItem, FALSE);
  255.             break;
  256.         case optionsMenu:
  257.             HandleOptionsMenu(menuItem);
  258.             break;
  259.         case modulesMenu:
  260.             HandleModulesMenu(menuItem);
  261.             break;
  262.         case insertMenu:
  263.             HandleInsertMenu(menuItem);
  264.             break;
  265.         case buildMenu:
  266.             HandleBuildMenu(menuItem);
  267.             break;
  268.         case speedMenu:
  269.             HandleSpeedMenu(menuItem);
  270.             break;
  271.     }
  272. }
  273.  
  274. void DoTheCloseThing(WindowPeek theWindow)
  275. /* a standard close procedure, called when "close" is chosen from File menu and when
  276.    a window is closed through its close box */
  277. {
  278.     short            kind;
  279.     
  280.     if (theWindow==0L)
  281.         return;
  282.     
  283.     kind = theWindow ? theWindow->windowKind : 0;
  284.     if (kind<0)        /* DA window or other system window */
  285.         CloseDeskAcc(kind);
  286.     else
  287.     {
  288.         if (WindowHasLayer((WindowPtr)theWindow))
  289.             CloseTheWindow((WindowPtr)theWindow);
  290.         else
  291.             DisposeWindow((WindowPtr)theWindow);
  292.         
  293.         AdjustMenus();
  294.     }
  295. }
  296.  
  297. static    void HandleAppleMenu(short menuItem)
  298. {
  299.     GrafPtr        savePort;
  300.     Str255        name;
  301.     
  302.     switch (menuItem)
  303.     {
  304.         case aboutItem:
  305.             if (!IndWindowExistsQQ(kAboutWindow))
  306.                 OpenTheIndWindow(kAboutWindow);
  307.             else
  308.                 MySelectWindow(GetIndWindowPtr(kAboutWindow));
  309.             break;
  310.         case aboutMSGItem:
  311.             if (!IndWindowExistsQQ(kAboutMSGWindow))
  312.                 OpenTheIndWindow(kAboutMSGWindow);
  313.             else
  314.                 MySelectWindow(GetIndWindowPtr(kAboutMSGWindow));
  315.             break;
  316.         case otherMSGItem:
  317.             if (!IndWindowExistsQQ(kOtherMSGWindow))
  318.                 OpenTheIndWindow(kOtherMSGWindow);
  319.             else
  320.                 MySelectWindow(GetIndWindowPtr(kOtherMSGWindow));
  321.             break;
  322.         case helpPointerItem:
  323.             if (!IndWindowExistsQQ(kHelpWindow))
  324.                 OpenTheIndWindow(kHelpWindow);
  325.             else
  326.                 MySelectWindow(GetIndWindowPtr(kHelpWindow));
  327.             break;
  328.         default:
  329.             if (menuItem > helpPointerItem+1)
  330.             {
  331.                 GetPort(&savePort);
  332.                 GetItem(gAppleMenu, menuItem, name);
  333.                 OpenDeskAcc(name);
  334.                 SetPort(savePort);
  335.             }
  336.             break;
  337.     }
  338. }
  339.  
  340. static    void HandleFileMenu(short menuItem)
  341. {
  342.     WindowPtr            theWindow;
  343.     TEHandle            hTE;
  344.     
  345.     switch (menuItem)
  346.     {
  347.         case newItem:
  348.             OpenTheIndWindow(kMainWindow);
  349.             break;
  350.         case openItem:
  351.             LoadSaveDispatch(TRUE, FALSE);
  352.             break;
  353.         case closeItem:
  354.             if ((theWindow=GetFrontDocumentWindow())!=0L)
  355.                 DoTheCloseThing((WindowPeek)theWindow);
  356.             else
  357.                 DoTheCloseThing((WindowPeek)FrontWindow());
  358.             break;
  359.         case saveItem:
  360.             LoadSaveDispatch(FALSE, TRUE);
  361.             break;
  362.         case saveAsItem:
  363.             LoadSaveDispatch(FALSE, FALSE);
  364.             break;
  365.         case pageSetupItem:
  366.             RemoveHilitePatch();
  367.             DoThePageSetup();
  368.             InstallHilitePatch();
  369.             break;
  370.         case printItem:
  371.             theWindow=GetFrontDocumentWindow();
  372.             if (WindowHasLayer(theWindow))
  373.             {
  374.                 hTE=GetWindowTE(theWindow);
  375.                 if (hTE!=0L)
  376.                 {
  377.                     RemoveHilitePatch();
  378.                     PrintText(hTE);
  379.                     InstallHilitePatch();
  380.                 }
  381.             }
  382.             else SysBeep(7);
  383.             break;
  384.         case quitItem:
  385.             gDone=ShutDownTheProgram();
  386.             break;
  387.     }
  388. }
  389.  
  390. static    void HandleEditMenu(short menuItem, Boolean alreadyPassedThrough)
  391. {
  392.     short            index;
  393.     WindowPtr        frontDoc;
  394.     enum DispatchError    resultCode;
  395.     
  396.     if (!alreadyPassedThrough)
  397.         index=(gFrontWindowIsOurs) ? gFrontWindowIndex : -1;
  398.     else
  399.     {
  400.         frontDoc=GetFrontDocumentWindow();
  401.         index=(frontDoc!=0L) ? GetWindowIndex(frontDoc) : -1;
  402.     }
  403.     
  404.     if (index>=0)
  405.     {
  406.         switch (menuItem)
  407.         {
  408.             case undoItem:        resultCode=UndoDispatch(index);            break;
  409.             case cutItem:        resultCode=CutDispatch(index);            break;
  410.             case copyItem:        resultCode=CopyDispatch(index);            break;
  411.             case pasteItem:        resultCode=PasteDispatch(index);        break;
  412.             case clearItem:        resultCode=ClearDispatch(index);        break;
  413.             case selectAllItem:    resultCode=SelectAllDispatch(index);    break;
  414.             default:            resultCode=kSuccess;                    break;
  415.         }
  416.         
  417.         if ((resultCode==kPassThrough) && (!alreadyPassedThrough))
  418.             HandleEditMenu(menuItem, TRUE);
  419.     }
  420.     else SystemEdit(menuItem-1);
  421. }
  422.  
  423. static    void HandleOptionsMenu(short menuItem)
  424. {
  425.     WindowPtr        mainWindow;
  426.     
  427.     switch (menuItem)
  428.     {
  429.         case resolveItem:
  430.             mainWindow=GetIndWindowPtr(kMainWindow);
  431.             
  432.             if (GetFrontDocumentWindow()!=mainWindow)
  433.                 MySelectWindow(mainWindow);
  434.             
  435.             HandleError(ParserDispatch(GetIndWindowPtr(kMainWindow)), FALSE, TRUE);
  436.             break;
  437.         case alwaysResolveItem:
  438.             gAlwaysResolve=!gAlwaysResolve;
  439.             AdjustMenus();
  440.             break;
  441.         case kantinuousItem:
  442.             Kantinuous();
  443.             break;
  444.     }
  445. }
  446.  
  447. static    void HandleModulesMenu(short menuItem)
  448. {
  449.     FSSpec            theFS;
  450.     Str255            theName;
  451.     OSErr            oe;
  452.     
  453.     switch (menuItem)
  454.     {
  455.         case modules_default:
  456.             if (!gUseDefault)
  457.             {
  458.                 theFS.name[0]=0x00;
  459.                 UseTheModule(&theFS, TRUE);
  460.             }
  461.             break;
  462.         case modules_other:
  463.             if (GetSourceFile(&theFS, BUILD_TYPE))
  464.             {
  465.                 UseTheModule(&theFS, FALSE);
  466.             }
  467.             break;
  468.         case modules_unused:
  469.             break;
  470.         default:
  471.             if (NUM_MODULES>0)
  472.             {
  473.                 GetItem(gModulesMenu, menuItem, theName);
  474.                 if ((oe=GetNamedModuleFS(&theFS, theName))==noErr)
  475.                 {
  476.                     UseTheModule(&theFS, FALSE);
  477.                 }
  478.                 else
  479.                 {
  480.                     HandleError(kModuleNotFound, FALSE, FALSE);
  481.                 }
  482.             }
  483.             break;
  484.     }
  485. }
  486.  
  487. static    void HandleInsertMenu(short menuItem)
  488. {
  489.     WindowPtr        mainWindow;
  490.     Str255            theName, fullName;
  491.     
  492.     mainWindow=GetIndWindowPtr(kMainWindow);
  493.     if (mainWindow==0L)
  494.     {
  495.         OpenTheIndWindow(kMainWindow);
  496.         mainWindow=GetIndWindowPtr(kMainWindow);
  497.     }
  498.     
  499.     if (GetFrontDocumentWindow()!=mainWindow)
  500.         MySelectWindow(mainWindow);
  501.     
  502.     if (gUseDefault)
  503.     {
  504.         switch (menuItem)
  505.         {
  506.             case sectionItem:
  507.                 InsertAfterEnd(mainWindow, "\p§ion");
  508.                 break;
  509.             case paragraphItem:
  510.                 InsertAfterEnd(mainWindow, "\p¶graph");
  511.                 break;
  512.             case sentenceItem:
  513.                 InsertAfterEnd(mainWindow, "\p&sentence");
  514.                 break;
  515.             case mainClauseItem:
  516.                 InsertAfterEnd(mainWindow, "\p&main-clause");
  517.                 break;
  518.             case introClauseItem:
  519.                 InsertAfterEnd(mainWindow, "\p&intro-clause");
  520.                 break;
  521.             case throwawayClauseItem:
  522.                 InsertAfterEnd(mainWindow, "\p&throwaway-clause");
  523.                 break;
  524.             case proofItem:
  525.                 InsertAfterEnd(mainWindow, "\p&proof");
  526.                 break;
  527.             case throwawaySentenceItem:
  528.                 InsertAfterEnd(mainWindow, "\p&throwaway-sentence");
  529.                 break;
  530.         }
  531.     }
  532.     else
  533.     {
  534.         GetItem(gInsertMenu, menuItem, theName);
  535.         fullName[0]=0x01;
  536.         fullName[1]='&';
  537.         AppendStr255(fullName, theName);
  538.         InsertAfterEnd(mainWindow, fullName);
  539.     }
  540.     
  541.     if (gAlwaysResolve)
  542.         HandleError(ParserDispatch(GetIndWindowPtr(kMainWindow)), FALSE, TRUE);
  543. }
  544.  
  545. static    void HandleBuildMenu(short menuItem)
  546. {
  547.     FSSpec            theFS;
  548.     WindowPtr        buildWindow;
  549.     OSErr            oe;
  550.     
  551.     buildWindow=GetIndWindowPtr(kBuildWindow);
  552.     if ((buildWindow!=0L) && (GetFrontDocumentWindow()!=buildWindow))
  553.     {
  554.         MySelectWindow(buildWindow);
  555.         SetCursor(&qd.arrow);
  556.     }
  557.     
  558.     switch (menuItem)
  559.     {
  560.         case build_new:
  561.             oe=DoNewModule();
  562.             if ((oe!=noErr) && (oe!=-1))    /* -1 = user cancel */
  563.                 HandleError(kCantCreateNewModule, FALSE, FALSE);
  564.             break;
  565.         case build_open:
  566.             oe=OpenTheModule(&theFS, FALSE, FALSE);
  567.             if ((oe!=noErr) && (oe!=-1))
  568.             {
  569.                 if (oe==-2)
  570.                     HandleError(kModuleTooLarge, FALSE, FALSE);
  571.                 else
  572.                     HandleError(kCantOpenModule, FALSE, FALSE);
  573.             }
  574.             break;
  575.         case build_new_ref:
  576.             DoNewRef(buildWindow);
  577.             break;
  578.         case build_new_instant:
  579.             DoNewInstantiation(buildWindow);
  580.             break;
  581.         case build_edit_ref:
  582.             if (RefHighlightedQQ(buildWindow))
  583.                 DoEditRef(buildWindow);
  584.             else
  585.                 DoEditInstantiation(buildWindow);
  586.             break;
  587.         case build_delete_ref:
  588.             if (RefHighlightedQQ(buildWindow))
  589.                 DoDeleteRef(buildWindow);
  590.             else
  591.                 DoDeleteInstantiation(buildWindow);
  592.             break;
  593.         case build_show_instant:
  594.             DealWithArrowClick(buildWindow, CurrentLineNumber(GetWindowTE(buildWindow)));
  595.             break;
  596.         case build_show_all_instant:
  597.             DoShowHideAll(buildWindow, TRUE);
  598.             break;
  599.         case build_hide_all_instant:
  600.             DoShowHideAll(buildWindow, FALSE);
  601.             break;
  602.     }
  603. }
  604.  
  605. static    void HandleSpeedMenu(short menuItem)
  606. {
  607.     switch (menuItem)
  608.     {
  609.         case delay0Item:
  610.             gSpeedDelay=0;
  611.             break;
  612.         case delay6Item:
  613.             gSpeedDelay=6;
  614.             break;
  615.         case delay12Item:
  616.             gSpeedDelay=12;
  617.             break;
  618.         case delay30Item:
  619.             gSpeedDelay=30;
  620.             break;
  621.         case delay60Item:
  622.             gSpeedDelay=60;
  623.             break;
  624.     }
  625.     
  626.     AdjustMenus();
  627. }
  628.  
  629. static    void EDItem(MenuHandle theMenu, short theItem, Boolean theCondition)
  630. {
  631.     if (theCondition)
  632.         EnableItem(theMenu, theItem);
  633.     else
  634.         DisableItem(theMenu, theItem);
  635. }
  636.  
  637. void RebuildModulesList(void)
  638. {
  639.     FSSpec            theFS;
  640.     
  641.     DeleteMenu(modulesMenu);
  642.     gModulesMenu=(MenuHandle)SafeReleaseResource((Handle)gModulesMenu);
  643.     gModulesMenu=GetMenu(modulesMenu);
  644.     InsertMenu(gModulesMenu, insertMenu);
  645.     if (BuildModulesList(gModulesMenu)!=noErr)
  646.     {
  647.         HandleError(kCantFindModulesFolder, FALSE, FALSE);
  648.         theFS.name[0]=0x00;
  649.         UseTheModule(&theFS, TRUE);    /* revert to built-in */
  650.     }
  651. }
  652.  
  653. void RebuildReferencesList(void)
  654. {
  655.     short            i;
  656.     FSSpec            theFS;
  657.     
  658.     gInsertMenu=(MenuHandle)SafeReleaseResource((Handle)gInsertMenu);
  659.     gInsertMenu=GetMenu(insertMenu);
  660.     InsertMenu(gInsertMenu, buildMenu);
  661.     if (!gUseDefault)
  662.     {
  663.         for (i=CountMItems(gInsertMenu); i>0; i--)
  664.             DelMenuItem(gInsertMenu, i);
  665.         if (BuildReferencesList(gInsertMenu, gModuleFS)!=noErr)
  666.         {
  667.             HandleError(kCantBuildReferenceList, FALSE, FALSE);
  668.             theFS.name[0]=0x00;
  669.             UseTheModule(&theFS, TRUE);    /* revert to built-in */
  670.         }
  671.     }
  672. }
  673.